<template>
	<view class="container">
		<view class="header">
			<view class="back" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<text class="title">我的收藏</text>
		</view>
		
		<view class="favorite-list">
			<view class="favorite-item" v-for="(item, index) in favoriteList" :key="index" @click="viewDetail(item)">
				<view class="item-header">
					<text class="item-title">{{item.title}}</text>
					<text class="item-date">{{item.date}}</text>
				</view>
				
				<text class="item-content">{{item.content}}</text>
				
				<view class="item-footer">
					<view class="item-tags">
						<text class="tag interpreted">已解梦</text>
					</view>
					<button class="uncollect-btn" @click.stop="handleUncollect(index)">
						<text class="icon-heart-filled">❤️</text>
					</button>
				</view>
			</view>
		</view>
		
		<view class="empty" v-if="favoriteList.length === 0">
			<image src="/static/empty-favorite.png" mode="aspectFit" class="empty-image"></image>
			<text class="empty-text">暂无收藏记录</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			favoriteList: [
				{
					id: 1,
					title: '飞翔梦',
					date: '03-15',
					content: '我梦见在一片星空下飞翔，感觉非常自由...'
				},
				{
					id: 2,
					title: '考试梦',
					date: '03-14',
					content: '梦见自己参加一场重要的考试，考场上充满紧张的气氛...'
				}
			]
		}
	},
	methods: {
		goBack() {
			uni.navigateBack()
		},
		viewDetail(item) {
			uni.navigateTo({
				url: '/pages/result/result?type=favorite&id=' + item.id
			})
		},
		handleUncollect(index) {
			uni.showModal({
				title: '取消收藏',
				content: '确定要取消收藏这个解梦吗？',
				success: (res) => {
					if (res.confirm) {
						this.favoriteList.splice(index, 1)
						uni.showToast({
							title: '已取消收藏',
							icon: 'success'
						})
					}
				}
			})
		}
	}
}
</script>

<style>
.container {
	min-height: 100vh;
	background: #f5f5f5;
	padding: 30rpx;
}

.header {
	display: flex;
	align-items: center;
	margin-bottom: 30rpx;
}

.back {
	margin-right: 20rpx;
}

.back-icon {
	font-size: 40rpx;
	color: #666;
}

.title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
}

.favorite-list {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.favorite-item {
	background: #fff;
	border-radius: 20rpx;
	padding: 20rpx;
}

.item-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 16rpx;
}

.item-title {
	font-size: 30rpx;
	font-weight: 500;
	color: #333;
}

.item-date {
	font-size: 24rpx;
	color: #999;
}

.item-content {
	font-size: 26rpx;
	color: #666;
	line-height: 1.6;
	margin-bottom: 16rpx;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.item-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.item-tags {
	display: flex;
	gap: 12rpx;
}

.tag {
	font-size: 22rpx;
	padding: 4rpx 16rpx;
	border-radius: 20rpx;
}

.interpreted {
	background: #e6f0ff;
	color: #4080ff;
}

.uncollect-btn {
	background: none;
	border: none;
	padding: 0;
	margin: 0;
	line-height: 1;
}

.icon-heart-filled {
	font-size: 36rpx;
}

.empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding-top: 200rpx;
}

.empty-image {
	width: 200rpx;
	height: 200rpx;
	margin-bottom: 20rpx;
}

.empty-text {
	font-size: 28rpx;
	color: #999;
}
</style> 